package com.example.interview.bean.vo;

import cn.hutool.core.net.Ipv4Util;
import com.alibaba.fastjson.JSON;
import com.example.interview.bean.tree.Tree;
import com.example.interview.bean.tree.TreeNode;

import java.util.List;
import java.util.concurrent.ConcurrentSkipListMap;

/**
 * @author ：superdyf
 * @date ：Created in 2021/10/8 14:06
 * @description：
 * @modified By：
 */
public class Test {
    static int l=0;
    static int r=0;
    static int all=0;
    public static void main(String[] args) {
//        tree();
        String ip="10.10.17.14";
        long ipnum=Ipv4Util.ipv4ToLong("10.10.17.14");
        System.out.println(ipnum);
        String dm_ip="dm"+ipnum;
        System.out.println(dm_ip);
        long ipnum_c=Long.parseLong(dm_ip.substring("dm".length()),16);
        String ip_c=Ipv4Util.longToIpv4(ipnum_c);
        System.out.println(ipnum_c);
        System.out.println(ip_c);
    }
    public static void inorder(TreeNode<String> root) {
        //中序遍历 左根右
        if(root==null) {
            return;
        }
        inorder(root.getLeft());
        System.out.println(root.getHash());
//        System.out.printf("%s-%s",root.getHash(),root.getE());
        inorder(root.getRight());
    }
    public static TreeNode<String> find(TreeNode<String> root,String s) {
        TreeNode<String> result=null;
        //中序遍历 左根右
        if(root==null) {
            return null;
        }
        if(Integer.toUnsignedLong(s.hashCode())<Integer.toUnsignedLong(root.getE().hashCode())){
            result=find(root.getLeft(),s);
        }else{
            result=find(root.getRight(),s);
        }
        if(s.equalsIgnoreCase(root.getE())){
            return root;
        }
        return result;
    }
    public static int height(TreeNode<String> root) {
        if(root==null) {
            return 0;
        }
        return Math.max(height(root.getLeft()),height(root.getRight()))+1;
    }
    public static int print(TreeNode<String> root, List<String> iter) {
        if(root==null) {
            return 0;
        }
        int l=print(root.getLeft(),iter);
        iter.add(root.getE());
        int r=print(root.getRight(),iter);
        return Math.max(l,r)+1;
    }
    public static String  label(TreeNode<String> root){
        if(null==root){
            return "nil";
        };
        StringBuilder builder=new StringBuilder();
        for (int i = 0; i <root.getHeight(); i++) {
            builder.append("*");
        }
        return builder.length()==0?"":builder.substring("*".length());
    }
    public static void tree(){
        Tree<String> tree=new Tree<>(new TreeNode<>("橘"));
        Tree<String> treere=new Tree<>(new TreeNode<>("橘"));
        String s="第三方华盛顿开发了还未开发就我和健康划分为复合型橘绿茶是看现场v房间里玩科技副会长程序自行车放开我今儿还发了解决客户反馈未回复骄傲的健康发送到划分为粉红色看得见哈福克斯冷冻机房哈";
        for (char c : s.toCharArray()) {
            String t=String.valueOf(c);
            tree.insert(t);
//            treere.insertByRecursion(t);
        }
        System.out.println(JSON.toJSONString(tree));
//        System.out.println(JSON.toJSONString(treere));
        /*traverse:{
            List<String> data=new ArrayList<>();
            System.out.println(print(tree.root,data));
            System.out.println(data.stream().map(e->Integer.toUnsignedLong(e.hashCode())).collect(Collectors.toList()));
            System.out.println(data);
        }
        compare:{
            for (int i = 0; i <50 ; i++) {
                StopWatch stopWatch=new StopWatch();
                stopWatch.start("tree");
                find(tree.root,"款");
                stopWatch.stop();
                stopWatch.start("for");
                for (char c : s.toCharArray()) {
                    if("款".equalsIgnoreCase(c+"")){
                        break;
                    }
                }
                stopWatch.stop();
                System.out.println(stopWatch.toString());
            }
        }*/
    }
    public static void map(){
        Bound s=new Bound(){};
    }
}
